#!/usr/bin/python3
# -*- coding: utf-8 -*-

import os, logging, json, aiohttp_jinja2
from io import BytesIO
from aiohttp import web

import db, proxyutils, settings
from coreweb import query_string

routes = web.RouteTableDef()
module_name = 'proxy'

@routes.get('/%s' % module_name)
# @aiohttp_jinja2.template('proxy.html')
async def proxy(request):
    data = proxyutils.load_proxy()
    data = dict(data, **request.app['view_commons'])
    return {'data': data, '__template__': 'proxy.html'}

@routes.get('/%s/reflash' % module_name)
async def proxy(request):
    result = proxyutils.reflash()
    if result['status']:
        return {'code': 0, 'msg': result['msg']}
    logging.error('failed to reflash: %s' % (result['msg']))
    return {'code': -1, 'msg': 'failed to reflash: %s' % (result['msg'])}
